
var xmlhttp;
var response = '';

$( addnew );



function addnew() {

  // Insert a DOM element object
  $('#myDiv').load('http://localhost/duoctu3/templates/acctKT/SDTTForm_add.php');
  

  var newPara = document.createElement( 'p' );
  var newParaText = document.createTextNode( "Here's a DOM element" );
  newPara.appendChild( newParaText );
  $('#myDiv').before( newPara );

  // Insert a string of HTML
  $('#myDiv').before( "<p>kkkk</p>" );

  // Insert a jQuery object
  $('#myDiv').before( $("<p>Here's a jQuery object</p>") );

  // Insert the output from a callback function
  $('#myDiv').before( sayHello );

  function sayHello() {
    return "<p>Hello! This is the output from a callback function</p>";
  }

}



function loadXMLDoc(url,cfunc)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}

function zShowMATK(str)
{
loadXMLDoc("gethint.php?q="+str,function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  alert("a");
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  });
}

function zzShowMATK(str)
{
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="iiiiiiii";
  return;
  }

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","http://localhost/duoctu3/classes/acct/js/gethint.php?q="+str,true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send();

}


function ShowMATK(q,dmtk)
{
	if (q.length==0)
	  { 
	  document.getElementById("txtHint").innerHTML="H&#227;y nh&#7853;p M&#227; TK";
	  return;
	  }

	var hint="";
	var nhap="";
	var stk = "";

	dmtk = dmtk.split(",");
	q=q.toLowerCase(); 
	len=q.length;
	var pos = -1;

		
	for (i = 0; i < dmtk.length; ++i) 
	{ 
		stk = dmtk[i].toLowerCase();
		pos = stk.indexOf(q);
		if (pos ==0)
		{
			if (hint=="")
			{
				hint = "<a onclick=\"getMATK('" + dmtk[i]+  "')"+ "\">"+dmtk[i]+"</a>";
			}
			else
			{
			hint = hint+"</br><a onclick=\"getMATK('" + dmtk[i]+  "')"+ "\">"+dmtk[i]+"</a>";
			
			}
		}
	}
	document.getElementById("txtHint").innerHTML=hint;

}

function getMATK(q)
{
	document.getElementById("matk").value=q;
	document.getElementById("txtHint").innerHTML="";

}



function ShowHint(q,aData, txtHint, txtMa)
{
if (q.length==0)
  { 
  document.getElementById(txtHint).innerHTML="H&#227;y nh&#7853;p M&#227; ";
  return;
  }

var hint="";
var stk = "";

dmtk = aData.split(",");
q=q.toLowerCase(); 
var pos = -1;

if (q=="*")
{
	for (i = 0; i < dmtk.length; ++i) 
	{ 
		if (hint=="")
		{
			hint = "<a onclick=\"getMA('" + dmtk[i]+  "','"+txtMa+"',"+ "'"+ txtHint+"')"+ "\">"+dmtk[i]+"</a>";
		}
		else
		{
		hint = hint+"</br><a onclick=\"getMA('" + dmtk[i]+  "','"+txtMa+"',"+ "'"+ txtHint+"')"+ "\">"+dmtk[i]+"</a>";

		}
	}
}
else
{
	for (i = 0; i < dmtk.length; ++i) 
	{ 
		stk = dmtk[i].toLowerCase();
		pos = stk.indexOf(q);
		if (pos ==0)
		{
			if (hint=="")
			{
				hint = "<a onclick=\"getMA('" + dmtk[i]+  "','"+txtMa+"',"+ "'"+ txtHint+"')"+ "\">"+dmtk[i]+"</a>";
			}
			else
			{
			hint = hint+"</br><a onclick=\"getMA('" + dmtk[i]+  "','"+txtMa+"',"+ "'"+ txtHint+"')"+ "\">"+dmtk[i]+"</a>";

			}
		}
	}
}
document.getElementById(txtHint).innerHTML=hint;
}



function getMA(q, txtMa, txtHint)
{
	var subdata = q.split("-");
	document.getElementById(txtMa).value=subdata[0];
	document.getElementById(txtHint).innerHTML=subdata[1];;

}

function testFieldNumber(field) {
    var regExpr = new RegExp("^\d*\.?\d*$");
    if (!regExpr.test(field)) {
      // Case of error
      field.value = "";
    }
}


function UpdateRecord(host, username, password, databaseName, year  )
  {
	  var matk=document.getElementById('matk').value;
	  var mant=document.getElementById('mant').value;
	  var madv = document.getElementById('madv').value;
	  var dknont = document.getElementById('dknont').value;
	  var dknovn = document.getElementById('dknovn').value;
      jQuery.ajax({
       type: "POST",
       url: "http://localhost/duoctu3/pages/acctKT/u_SDTT.php",
	   data: {host: host, username: username, password: password, databaseName: databaseName, year: year, matk:matk },
       cache: false,
       success: function(response)
       {
         alert("Ghi xong!");

       }
     });



